/**
  ******************************************************************************
  * @file    
  * @author  
  * @version 
  * @date    
  * @brief   
  ******************************************************************************
	* @attention
  *
  * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
  *
  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  * You may not use this file except in compliance with the License.
  * You may obtain a copy of the License at:
  *
  *        http://www.st.com/software_license_agreement_liberty_v2
  *
  * Unless required by applicable law or agreed to in writing, software 
  * distributed under the License is distributed on an "AS IS" BASIS, 
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  *
  ******************************************************************************
  */

#include "hwconf.h"

/**
  * @brief  Configures the GPIOs.
  * @param  None
  * @retval None
  */
void PWR_Config(void)
{
	/* Power enable */
  *(__IO uint32_t *) RCC_APB1ENR_PWREN_BB = (uint32_t)SET;
  	
	/* Enable the Fast Wake-Up mode */
	*(__IO uint32_t *) PWR_CR_FWU_BB = (uint32_t)SET;
	
	/* Enable the Ultra Low-power mode */
	*(__IO uint32_t *) PWR_CR_ULP_BB = (uint32_t)SET;
	
	/* Power disable */
  *(__IO uint32_t *) RCC_APB1ENR_PWREN_BB = (uint32_t)RESET;
	
	/* Set the 1.8 core voltage range */
	PWR_SetVoltageRange(RESET);
}

/**
  * @brief  Configures the PWR.
  * @param  lowPower: SET to have regulator voltage range 1.5V, RESET to have 1.8V
  * @retval None
  */
void PWR_SetVoltageRange(FlagStatus lowPower)
{
	uint32_t temp_reg_value = 0;
	
	/* Power enable */
  *(__IO uint32_t *) RCC_APB1ENR_PWREN_BB = (uint32_t)SET;
  
	/* Read the RCC Internal Clock Sources Calibration Register */
	temp_reg_value = PWR->CR;
	
  /* Clear MSIRANGE[2:0] bits */
  temp_reg_value &= ~PWR_CR_VOS;
  	
	if (lowPower == RESET)
	{
	  temp_reg_value |= PWR_CR_VOS_0;
	}
	else {
		temp_reg_value |= PWR_CR_VOS_1;
	}
	
	/* Save the configuration */
	PWR->CR = temp_reg_value;
		
  /* Wait Until the Voltage Regulator is ready */
  while((*(__IO uint32_t *)PWR_CSR_VOSF_BB) != RESET)
  {
  }
	
	/* Power disable */
  *(__IO uint32_t *) RCC_APB1ENR_PWREN_BB = (uint32_t)RESET;
}


/************************************** EOF *********************************/
